namespace gg {
    export type AnyFunType = (...args) => any;

    const tinyNum = 0.0000000001;
    const sliceArr = function (a) { //don't use Array.prototype.slice.call(target, 0) because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll()
        var b = [],
            l = a.length,
            i;
        for (i = 0; i !== l; b.push(a[i++])) { }
        return b;
    };
    const emptyFunc = function () { };
    const isArray = (function () { //works around issues in iframe environments where the Array global isn't shared, thus if the object originates in a different window/iframe, "(obj instanceof Array)" will evaluate false. We added some speed optimizations to avoid Object.prototype.toString.call() unless it's absolutely necessary because it's VERY slow (like 20x slower)
        var toString = Object.prototype.toString,
            array = toString.call([]);
        return function (obj) {
            return obj != null && (obj instanceof Array || (typeof (obj) === "object" && !!obj.push && toString.call(obj) === array));
        };
    }());
    let gTicker: Ticker;

	/*
	 * ----------------------------------------------------------------
	 * EventDispatcher
	 * ----------------------------------------------------------------
	 */
    export class EventDispatcher {
        listeners: { [key: string]: { c: AnyFunType, s: any, up: boolean, pr: number }[] };
        eventTarget: any;
        constructor(target?) {
            this.listeners = {};
            this.eventTarget = target || this;
        }

        addEventListener(type: string, callback: AnyFunType, scope?: any, useParam?: boolean, priority?: number) {
            priority = priority || 0;
            var list = this.listeners[type],
                index = 0,
                listener, i;
            if (list == null) {
                this.listeners[type] = list = [];
            }
            i = list.length;
            while (--i > -1) {
                listener = list[i];
                if (listener.c === callback && listener.s === scope) {
                    list.splice(i, 1);
                } else if (index === 0 && listener.pr < priority) {
                    index = i + 1;
                }
            }
            list.splice(index, 0, { c: callback, s: scope, up: useParam, pr: priority });
        };

        removeEventListener(type: string, callback?) {
            var list = this.listeners[type], i;
            if (list) {
                i = list.length;
                while (--i > -1) {
                    if (list[i].c === callback) {
                        list.splice(i, 1);
                        return;
                    }
                }
            }
        };

        dispatchEvent(type: string) {
            var list = this.listeners[type],
                i, t;
            if (list) {
                i = list.length;
                if (i > 1) {
                    list = list.slice(0); //in case addEventListener() is called from within a listener/callback (otherwise the index could change, resulting in a skip)
                }
                t = this.eventTarget;
                while (--i > -1) {
                    let listener = list[i];
                    if (listener) {
                        if (listener.up) {
                            listener.c.call(listener.s || t, { type: type, target: t });
                        } else {
                            listener.c.call(listener.s || t);
                        }
                    }
                }
            }
        };

    }

	/*
	 * ----------------------------------------------------------------
	 * Ticker
	 * ----------------------------------------------------------------
	 */
    var reqAnimFrameFun = window.requestAnimationFrame,
        cancelAnimFrameFun = window.cancelAnimationFrame,
        getTime = Date.now || function () { return new Date().getTime(); },
        lastUpdateTime = getTime();


    export class Ticker extends EventDispatcher {
        public static readonly TickWord = "tick"; //helps reduce gc burden

        time: number;
        frame: number;

        fps: (value?: number) => number;
        sleep: () => void;
        wake: (seamless?: boolean) => void;
        tick: () => void;
        lagSmoothing: (threshold: number, adjustedLag: number) => boolean;
        manual: (this: Ticker, manual: boolean) => void;

        constructor(fpsNumber = 60) {
            super();

            const tickWord = Ticker.TickWord; //helps reduce gc burden
            let startTime = getTime();
            let lagThreshold = 500;
            let adjustedLag = 33;
            let fps: number;
            let reqFun: (...arg) => any;
            let timerId: number;
            let gap: number;
            let nextTime: number;
            let manual: boolean = false;
            let gTickerActive: boolean = false;

            const tickFun = this.tick = () => {
                if (!gTickerActive) {
                    return;
                }

                let elapsed = getTime() - lastUpdateTime;
                let overlap: number;
                let dispatch: boolean;

                if (elapsed > lagThreshold) {
                    startTime += elapsed - adjustedLag;
                }

                lastUpdateTime += elapsed;
                this.time = (lastUpdateTime - startTime) / 1000;
                overlap = this.time - nextTime;

                if (!fps || overlap > 0 || manual === true) {
                    this.frame++;
                    nextTime += overlap + (overlap >= gap ? 0.004 : gap - overlap);
                    dispatch = true;
                }

                if (manual !== true) { //make sure the request is made before we dispatch the "tick" event so that timing is maintained. Otherwise, if processing the "tick" requires a bunch of time (like 15ms) and we're using a setTimeout() that's based on 16.7ms, it'd technically take 31.7ms between frames otherwise.
                    timerId = reqFun(tickFun);
                }

                if (dispatch) {
                    this.dispatchEvent(tickWord);
                }
            };

            this.sleep = function (this: Ticker) {
                if (!gTickerActive) {
                    return
                }
                if (timerId == null) {
                    return;
                }

                if (!reqAnimFrameFun) {
                    clearTimeout(timerId);
                } else {
                    cancelAnimFrameFun(timerId);
                }

                gTickerActive = false;
                timerId = null;
                reqFun = emptyFunc;
            };

            this.wake = function (this: Ticker, seamless?: boolean) {
                if (gTickerActive) {
                    return
                }
                gTickerActive = true;

                if (timerId !== null) {
                    this.sleep();
                } else if (seamless) {
                    startTime += -lastUpdateTime + (lastUpdateTime = getTime());
                } else if (this.frame > 10) { //don't trigger lagSmoothing if we're just waking up, and make sure that at least 10 frames have elapsed because of the iOS bug that we work around below with the 1.5-second setTimout().
                    lastUpdateTime = getTime() - lagThreshold + 5;
                }

                if (fps === 0) {
                    reqFun = emptyFunc;
                } else {
                    if (reqAnimFrameFun) {
                        reqFun = reqAnimFrameFun;
                    } else {
                        reqFun = (f) => { return setTimeout(f, ((nextTime - this.time) * 1000 + 1) | 0); }
                    }
                }

                tickFun();
            };

            this.manual = function (this: Ticker, value: boolean) {
                if (!arguments.length) {
                    return manual;
                }
                manual = !!value;
            };

            this.fps = function (this: Ticker, value?: number) {
                if (!arguments.length) {
                    return fps;
                }
                if (fps === undefined) {
                    value = 60;
                }
                fps = value;
                gap = 1 / (fps === 0 ? 60 : fps);
                nextTime = this.time + gap;
                this.wake();
            };

            this.lagSmoothing = function (this: Ticker, thresholdParam: number, adjustedLagParam: number) {
                //if lagSmoothing() is called with no arguments, treat it like a getter that returns a boolean indicating if it's enabled or not. This is purposely undocumented and is for internal use.
                if (!arguments.length) {
                    return (lagThreshold < 1 / tinyNum);
                }
                lagThreshold = thresholdParam || (1 / tinyNum); //zero should be interpreted as basically unlimited
                adjustedLag = Math.min(adjustedLagParam, lagThreshold, 0);
            };

            this.time = this.frame = 0;

            this.manual(false);
            this.fps(fpsNumber);
        }
    }


	/*
	 * ----------------------------------------------------------------
	 * Animation
	 * ----------------------------------------------------------------
	 */



    export interface TweenVars {
        data?: any;
        delay?: number;
        immediateRender?: boolean;
        reversed?: boolean;
        useFrames?: boolean;
        paused?: boolean;
        callbackScope?: any;
        overwrite?: number | string;
        startAt?: any;

        lazy?: boolean;
        runBackwards?: boolean;
        onUpdate?: AnyFunType;
        onStart?: AnyFunType;
        onComplete?: AnyFunType;
        onCompleteParams?: any;
        onReverseComplete?: AnyFunType;
        onReverseCompleteParams?: any;

        onOverwrite?: AnyFunType;
        onUpdateParams?: AnyFunType;
        onUpdateScope?: AnyFunType;
        stringFilter?: AnyFunType;

        autoRemoveChildren?: boolean;
        smoothChildTiming?: boolean;
        tweens?: Animation[];
        align?: boolean;
        stagger?: boolean;
    }

    export class Animation {
        vars: TweenVars;
        data: any;

        _totalDuration_: number;
        _duration_: number;
        _delay_: number;
        _timeScale_: number;
        _active_: boolean;
        _reversed_: boolean;
        _time_: number;
        _totalTime_: number;
        _initted_: boolean;
        _rawPrevTime_: number;
        _dirty_: boolean;
        _paused_: boolean;
        _startTime_: number;
        _existOnUpdate_: boolean;
        _pauseTime_: number;
        _ratio_: number;
        _gc_: boolean;

        _timeline_: SimpleTimeline;
        timeline: SimpleTimeline;

        _first_: Animation;
        _last_: Animation;
        _prev_: Animation;
        _next_: Animation;
        _recent_: Animation;

        static ticker: Ticker;
        static rootTimeline: SimpleTimeline;
        static rootFramesTimeline: SimpleTimeline;

        constructor(duration?: number, vars?: TweenVars) {
            this._duration_ = this._totalDuration_ = duration || 0;

            this.vars = vars = vars || {};
            this.data = vars.data;
            this._delay_ = vars.delay || 0;
            this._active_ = (vars.immediateRender === true);
            this._reversed_ = (vars.reversed === true);
            this._timeScale_ = 1;

            if (!gRootTimeline) {
                return;
            }

            let tl = vars.useFrames ? gRootFramesTimeline : gRootTimeline;
            tl.add(this, tl._time_);

            if (vars.paused) {
                this.paused(true);
            }
        }

        play(from?: number, suppressEvents?: boolean) {
            if (from != null) {
                this.seek(from, suppressEvents);
            }
            return this.reversed(false).paused(false);
        };

        pause(atTime?: number, suppressEvents?: boolean) {
            if (atTime != null) {
                this.seek(atTime, suppressEvents);
            }
            return this.paused(true);
        };

        resume(from?: number, suppressEvents?: boolean) {
            if (from != null) {
                this.seek(from, suppressEvents);
            }
            return this.paused(false);
        };

        seek(time?: number, suppressEvents?: boolean) {
            return this.totalTime(time, suppressEvents !== false);
        };

        restart(includeDelay?: boolean, suppressEvents?: boolean) {
            return this.reversed(false).paused(false).totalTime(includeDelay ? -this._delay_ : 0, (suppressEvents !== false), true);
        };

        reverse(from?: number, suppressEvents?: boolean) {
            if (from != null) {
                this.seek((from || this.totalDuration()), suppressEvents);
            }
            return this.reversed(true).paused(false);
        };

        render(time, suppressEvents?, force?) {
            //stub - we override this method in subclasses.
        };

        invalidate() {
            this._time_ = this._totalTime_ = 0;
            this._initted_ = this._gc_ = false;
            this._rawPrevTime_ = -1;
            if (!this.timeline) {
                this._enabled_(true);
            }
            return this;
        };

        isActive(): boolean {
            let tl = this._timeline_, //the 2 root timelines won't have a _timeline_; they're always active.
                startTime = this._startTime_,
                rawTime: number;
            return (!tl || (!this._gc_ && !this._paused_ && tl.isActive() && (rawTime = tl.rawTime(true)) >= startTime && rawTime < startTime + this.totalDuration() / this._timeScale_ - 0.0000001));
        };

        _enabled_(enabled: boolean, ignoreTimeline?: boolean) {
            this._gc_ = !enabled;
            this._active_ = this.isActive();
            if (ignoreTimeline !== true) {
                if (enabled && !this.timeline) {
                    this._timeline_.add(this, this._startTime_ - this._delay_);
                } else if (!enabled && this.timeline) {
                    this._timeline_._remove_(this, true);
                }
            }
            return false;
        };


        _kill_(vars?, target?) {
            return this._enabled_(false, false);
        };

        kill(vars?, target?) {
            this._kill_(vars, target);
            return this;
        };

        _uncache_(includeSelf: boolean) {
            let tween: Animation = includeSelf ? this : this.timeline;
            while (tween) {
                tween._dirty_ = true;
                tween = tween.timeline;
            }
            return this;
        };

        _swapSelfInParams_(params: any[]) {
            let i = params.length,
                copy = params.concat();
            while (--i > -1) {
                if (params[i] === "{self}") {
                    copy[i] = this;
                }
            }
            return copy;
        };

        _callback_(type: string) {
            const v = this.vars;
            const callback: AnyFunType = v[type];
            const params: any[] = v[type + "Params"];
            const scope = v[type + "Scope"] || v.callbackScope || this;
            const l = params ? params.length : 0;

            switch (l) { //speed optimization; call() is faster than apply() so use it when there are only a few parameters (which is by far most common). Previously we simply did var v = this.vars; v[type].apply(v[type + "Scope"] || v.callbackScope || this, v[type + "Params"] || _blankArray);
                case 0: callback.call(scope); break;
                case 1: callback.call(scope, params[0]); break;
                case 2: callback.call(scope, params[0], params[1]); break;
                default: callback.apply(scope, params);
            }
        };

        //----Animation getters/setters --------------------------------------------------------
        // type  is startWith 'on'
        eventCallback(type: string, callback?: AnyFunType, params?: any[], scope?: any) {
            if ((type || "").substr(0, 2) === "on") {
                var v = this.vars;
                if (arguments.length === 1) {
                    return v[type];
                }
                if (callback == null) {
                    delete v[type];
                } else {
                    v[type] = callback;
                    v[type + "Params"] = (isArray(params) && params.join("").indexOf("{self}") !== -1) ? this._swapSelfInParams_(params) : params;
                    v[type + "Scope"] = scope;
                }
                if (type === "onUpdate") {
                    this._existOnUpdate_ = true;
                }
            }
            return this;
        };

        delay(value: number) {
            if (this._timeline_.smoothChildTiming) {
                this.startTime(this._startTime_ + value - this._delay_);
            }
            this._delay_ = value;
            return this;
        };

        duration(value?: number): number {
            if (!arguments.length) {
                this._dirty_ = false;
                return this._duration_;
            }
            this._duration_ = this._totalDuration_ = value;
            this._uncache_(true); //true in case it's a TweenMax or TimelineMax that has a repeat - we'll need to refresh the totalDuration.
            if (this._timeline_.smoothChildTiming) if (this._time_ > 0) if (this._time_ < this._duration_) if (value !== 0) {
                this.totalTime(this._totalTime_ * (value / this._duration_), true);
            }
            return this._duration_;
        };

        totalDuration(value?: number): number {
            this._dirty_ = false;
            return (!arguments.length) ? this._totalDuration_ : this.duration(value);
        };

        time(value?: number, suppressEvents?: boolean) {
            if (!arguments.length) {
                return this._time_;
            }
            if (this._dirty_) {
                this.totalDuration();
            }
            return this.totalTime((value > this._duration_) ? this._duration_ : value, suppressEvents);
        };

        totalTime(time?: number, suppressEvents?: boolean, uncapped?: boolean) {
            if (!arguments.length) {
                return this._totalTime_;
            }

            if (this._timeline_) {
                if (time < 0 && !uncapped) {
                    time += this.totalDuration();
                }
                if (this._timeline_.smoothChildTiming) {
                    if (this._dirty_) {
                        this.totalDuration();
                    }
                    const totalDuration = this._totalDuration_;
                    let tl = this._timeline_;
                    if (time > totalDuration && !uncapped) {
                        time = totalDuration;
                    }
                    this._startTime_ = (this._paused_ ? this._pauseTime_ : tl._time_) - ((!this._reversed_ ? time : totalDuration - time) / this._timeScale_);
                    if (!tl._dirty_) { //for performance improvement. If the parent's cache is already dirty, it already took care of marking the ancestors as dirty too, so skip the function call here.
                        this._uncache_(false);
                    }
                    //in case any of the ancestor timelines had completed but should now be enabled, we should reset their totalTime() which will also ensure that they're lined up properly and enabled. Skip for animations that are on the root (wasteful). Example: a TimelineLite.exportRoot() is performed when there's a paused tween on the root, the export will not complete until that tween is unpaused, but imagine a child gets restarted later, after all [unpaused] tweens have completed. The startTime of that child would get pushed out, but one of the ancestors may have completed.
                    if (tl._timeline_) {
                        while (tl._timeline_) {
                            if (tl._timeline_._time_ !== (tl._startTime_ + tl._totalTime_) / tl._timeScale_) {
                                tl.totalTime(tl._totalTime_, true);
                            }
                            tl = tl._timeline_;
                        }
                    }
                }
                if (this._gc_) {
                    this._enabled_(true, false);
                }
                if (this._totalTime_ !== time || this._duration_ === 0) {
                    if (lazyTweensArr.length) {
                        lazyRenderTweens();
                    }
                    this.render(time, suppressEvents, false);
                    if (lazyTweensArr.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when someone calls seek() or time() or progress(), they expect an immediate render.
                        lazyRenderTweens();
                    }
                }
            }
            return this._totalTime_;
        };

        progress(value?: number, suppressEvents?: boolean) {
            var duration = this.duration();
            return (!arguments.length) ? (duration ? this._time_ / duration : this._ratio_) : this.totalTime(duration * value, suppressEvents);
        };

        totalProgress(value?: number, suppressEvents?: boolean) {
            var duration = this.duration();
            return (!arguments.length) ? (duration ? this._time_ / duration : this._ratio_) : this.totalTime(duration * value, suppressEvents);
        };

        startTime(value?: number) {
            if (!arguments.length) {
                return this._startTime_;
            }
            if (value !== this._startTime_) {
                this._startTime_ = value;
                if (this.timeline) if (this.timeline.sortChildren) {
                    this.timeline.add(this, value - this._delay_); //ensures that any necessary re-sequencing of Animations in the timeline occurs to make sure the rendering order is correct.
                }
            }
            return this._startTime_;
        };

        endTime(includeRepeats: boolean) {
            return this._startTime_ + ((includeRepeats != false) ? this.totalDuration() : this.duration()) / this._timeScale_;
        };

        timeScale(value: number) {
            if (!arguments.length) {
                return this._timeScale_;
            }
            value = value || tinyNum; //can't allow zero because it'll throw the math off
            if (this._timeline_ && this._timeline_.smoothChildTiming) {
                let pauseTime = this._pauseTime_;
                let t = (pauseTime || pauseTime === 0) ? pauseTime : this._timeline_.totalTime();
                this._startTime_ = t - ((t - this._startTime_) * this._timeScale_ / value);
            }
            this._timeScale_ = value;
            let tl = this.timeline;
            while (tl && tl.timeline) { //must update the duration/totalDuration of all ancestor timelines immediately in case in the middle of a render loop, one tween alters another tween's timeScale which shoves its startTime before 0, forcing the parent timeline to shift around and shiftChildren() which could affect that next tween's render (startTime). Doesn't matter for the root timeline though.
                tl._dirty_ = true;
                tl.totalDuration();
                tl = tl.timeline;
            }
            return this._timeScale_;
        };

        reversed(value: boolean) {
            if (value != this._reversed_) {
                this._reversed_ = value;
                this.totalTime(((this._timeline_ && !this._timeline_.smoothChildTiming) ? this.totalDuration() - this._totalTime_ : this._totalTime_), true);
            }
            return this;
        };

        paused(value: boolean) {
            const tl = this._timeline_;

            if (value != this._paused_ && tl) {
                let raw = tl.rawTime();
                let elapsed = raw - this._pauseTime_;
                if (!value && tl.smoothChildTiming) {
                    this._startTime_ += elapsed;
                    this._uncache_(false);
                }
                this._pauseTime_ = value ? raw : null;
                this._paused_ = value;
                this._active_ = this.isActive();
                if (!value && elapsed !== 0 && this._initted_ && this.duration()) {
                    raw = tl.smoothChildTiming ? this._totalTime_ : (raw - this._startTime_) / this._timeScale_;
                    this.render(raw, (raw === this._totalTime_), true); //in case the target's properties changed via some other tween or manual update by the user, we should force a render.
                }
            }

            if (this._gc_ && !value) {
                this._enabled_(true, false);
            }
            return this;
        };


    }

    gTicker = Animation.ticker = new Ticker();
    let Animation_prototype = Animation.prototype;
    Animation_prototype._dirty_ = Animation_prototype._gc_ = Animation_prototype._initted_ = Animation_prototype._paused_ = false;
    Animation_prototype._totalTime_ = Animation_prototype._time_ = 0;
    Animation_prototype._rawPrevTime_ = -1;
    Animation_prototype._next_ = Animation_prototype._last_ = Animation_prototype._existOnUpdate_ = Animation_prototype._timeline_ = Animation_prototype.timeline = null;
    Animation_prototype._paused_ = false;

	/*
	 * ----------------------------------------------------------------
	 * SimpleTimeline
	 * ----------------------------------------------------------------
	 */

    export class SimpleTimeline extends Animation {
        autoRemoveChildren: boolean;
        smoothChildTiming: boolean;
        sortChildren: boolean;

        constructor(vars?: TweenVars) {
            super(0, vars);
            this.autoRemoveChildren = this.smoothChildTiming = true;
        }

        add(child: Animation, position: number, align?: string, stagger?: number) {
            let prevTween: Animation;
            let startTime: number;

            child._startTime_ = position || 0 + child._delay_;
            if (child._paused_ && this !== child._timeline_) {
                //we only adjust the _pauseTime if it wasn't in this timeline already. Remember, sometimes a tween will be inserted again into the same timeline when its startTime is changed so that the tweens in the TimelineLite/Max are re-ordered properly in the linked list (so everything renders in the proper order).
                child._pauseTime_ = this.rawTime() - (child._timeline_.rawTime() - child._pauseTime_);
            }

            if (child.timeline) {
                child.timeline._remove_(child, true); //removes from existing timeline so that it can be properly added to this one.
            }
            child.timeline = child._timeline_ = this;
            if (child._gc_) {
                child._enabled_(true, true);
            }
            prevTween = this._last_;
            if (this.sortChildren) {
                startTime = child._startTime_;
                while (prevTween && prevTween._startTime_ > startTime) {
                    prevTween = prevTween._prev_;
                }
            }
            if (prevTween) {
                child._next_ = prevTween._next_;
                prevTween._next_ = child;
            } else {
                child._next_ = this._first_;
                this._first_ = child;
            }
            if (child._next_) {
                child._next_._prev_ = child;
            } else {
                this._last_ = child;
            }
            child._prev_ = prevTween;
            this._recent_ = child;
            if (this._timeline_) {
                this._uncache_(true);
            }
            return this;
        };

        insert(child: Animation, position: number, align?: string, stagger?: number) { // 插入排序
            let prevTween: Animation;
            let startTime: number;

            child._startTime_ = position || 0 + child._delay_;
            if (child._paused_ && this !== child._timeline_) {
                //we only adjust the _pauseTime if it wasn't in this timeline already. Remember, sometimes a tween will be inserted again into the same timeline when its startTime is changed so that the tweens in the TimelineLite/Max are re-ordered properly in the linked list (so everything renders in the proper order).
                child._pauseTime_ = this.rawTime() - (child._timeline_.rawTime() - child._pauseTime_);
            }

            if (child.timeline) {
                child.timeline._remove_(child, true); //removes from existing timeline so that it can be properly added to this one.
            }
            child.timeline = child._timeline_ = this;
            if (child._gc_) {
                child._enabled_(true, true);
            }
            prevTween = this._last_;
            if (this.sortChildren) {
                startTime = child._startTime_;
                while (prevTween && prevTween._startTime_ > startTime) {
                    prevTween = prevTween._prev_;
                }
            }
            if (prevTween) {
                child._next_ = prevTween._next_;
                prevTween._next_ = child;
            } else {
                child._next_ = this._first_;
                this._first_ = child;
            }
            if (child._next_) {
                child._next_._prev_ = child;
            } else {
                this._last_ = child;
            }
            child._prev_ = prevTween;
            this._recent_ = child;
            if (this._timeline_) {
                this._uncache_(true);
            }
            return this;
        };

        _remove_(tween: Animation, skipDisable: boolean) { // 链表的删除
            if (tween.timeline === this) {
                if (!skipDisable) {
                    tween._enabled_(false, true);
                }

                if (tween._prev_) {
                    tween._prev_._next_ = tween._next_;
                } else if (this._first_ === tween) {
                    this._first_ = tween._next_;
                }
                if (tween._next_) {
                    tween._next_._prev_ = tween._prev_;
                } else if (this._last_ === tween) {
                    this._last_ = tween._prev_;
                }
                tween._next_ = tween._prev_ = tween.timeline = null;
                if (tween === this._recent_) {
                    this._recent_ = this._last_;
                }

                if (this._timeline_) {
                    this._uncache_(true);
                }
            }
            return this;
        };

        render(time: number, suppressEvents?: boolean, force?: boolean) {
            let tween = this._first_;
            let next: Animation;
            this._totalTime_ = this._time_ = this._rawPrevTime_ = time;

            while (tween) {
                next = tween._next_; //record it here because the value could change after rendering...
                if (tween._active_ || (time >= tween._startTime_ && !tween._paused_ && !tween._gc_)) {
                    if (!tween._reversed_) {
                        tween.render((time - tween._startTime_) * tween._timeScale_, suppressEvents, force);
                    } else {
                        tween.render(((!tween._dirty_) ? tween._totalDuration_ : tween.totalDuration()) - ((time - tween._startTime_) * tween._timeScale_), suppressEvents, force);
                    }
                }
                tween = next;
            }
        };

        rawTime(wrapRepeats?: boolean) {
            return this._totalTime_;
        };

    }
    var SimpleTimeline_prototype = SimpleTimeline.prototype;
    SimpleTimeline_prototype.kill()._gc_ = false;
    SimpleTimeline_prototype._first_ = SimpleTimeline_prototype._last_ = SimpleTimeline_prototype._recent_ = null;
    SimpleTimeline_prototype.sortChildren = false;


	/*
	 * ----------------------------------------------------------------
	 * TweenLite
	 * ----------------------------------------------------------------
	 */

    //t - target 		[object]
    //p - property 		[string]
    //s - start			[number]
    //c - change		[number]
    //f - isFunction	[boolean]
    //n - name			[string]
    //pg - isPlugin 	[boolean]
    //pr - priority		[number]
    //m - mod           [function | 0]
    interface TweenPropType {
        t: any;
        p: string;
        s: number;
        c: number;
        f: boolean;
        n: string;
        pg: boolean;
        pr: number;
        m: number | AnyFunType;
        _prev_?: TweenPropType;
        _next_?: TweenPropType;
    }



    export class TweenLite extends Animation {
        target: any;

        _overwrite_: number;

        _propLookup_: any[] | { [key: string]: {} };
        _siblings_: TweenLite[] | TweenLite[][];
        _targets_: any[];
        _overwrittenProps: any;
        _startAt_: TweenLite;
        _firstPT: TweenPropType;
        _lazy_: [number, boolean] | boolean;
        _notifyPluginsOfEnabled: boolean;

        static version: string;
        static defaultOverwrite: string;
        static autoSleep: number;
        static _internals_: any;
        static _plugins_: {};

        static lagSmoothing: (threshold: any, adjustedLag: any) => void;
        static render: () => void;
        static onOverwrite: () => void;
        static to: (target: any, duration: any, vars: any) => TweenLite;
        static from: (target: any, duration: any, vars: any) => TweenLite;
        static fromTo: (target: any, duration: any, fromVars: any, toVars: any) => TweenLite;
        static delayedCall: (delay: any, callback: any, params?: any, scope?: any, useFrames?: any) => TweenLite;
        static set: (target: any, vars: any) => TweenLite;
        static getTweensOf: (target: any, onlyActive?: any) => any;
        static killTweensOf: (target: any, onlyActive: any, vars: any) => void;
        static killDelayedCallsTo: (target: any, onlyActive: any, vars: any) => void;

        constructor(target: any, duration: number, vars: TweenVars) {
            super(duration, vars);
            this.render = TweenLite.prototype.render; //speed optimization (avoid prototype lookup on this "hot" method)

            if (target == null) {
                throw "Cannot tween a null target.";
            }

            this.target = target;

            let overwrite = this.vars.overwrite;

            this._overwrite_ = overwrite = (overwrite == null) ? overwriteLookupMap[TweenLite.defaultOverwrite] : (typeof (overwrite) === "number") ? overwrite >> 0 : overwriteLookupMap[overwrite];

            if (isArray(target)) {
                let targets: any[] = this.target = sliceArr(target);  //don't use Array.prototype.slice.call(target, 0) because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll()
                this._propLookup_ = [];
                this._siblings_ = [];
                for (let i = 0; i < targets.length; i++) {
                    let targ = targets[i];
                    if (!targ) {
                        targets.splice(i--, 1);
                        continue;
                    } else if (isArray(targ)) {
                        targets.splice(i--, 1);
                        this._targets_ = targets = targets.concat(sliceArr(targ));
                        continue;
                    }
                    this._siblings_[i] = targetRegister(targ, this, false);
                    const siblings = <TweenLite[][]>this._siblings_;
                    if (overwrite === 1) if (siblings[i].length > 1) {
                        applyOverwriteHook(targ, this, null, 1, siblings[i]);
                    }
                }

            } else {
                this._propLookup_ = {};
                this._siblings_ = targetRegister(target, this, false);
                if (overwrite === 1) if (this._siblings_.length > 1) {
                    applyOverwriteHook(target, this, null, 1, this._siblings_);
                }
            }
            if (this.vars.immediateRender || (duration === 0 && this._delay_ === 0 && this.vars.immediateRender !== false)) {
                this._time_ = -tinyNum; //forces a render without having to set the render() "force" parameter to true because we want to allow lazying by default (using the "force" parameter always forces an immediate full render)
                this.render(Math.min(0, -this._delay_)); //in case delay is negative
            }
        }

        _init_() {
            let v = this.vars;
            let op = this._overwrittenProps;
            let dur = this._duration_;
            let immediate = !!v.immediateRender;
            let startVars: TweenVars;

            if (v.startAt) {
                if (this._startAt_) {
                    this._startAt_.render(-1, true); //if we've run a startAt previously (when the tween instantiated), we should revert it so that the values re-instantiate correctly particularly for relative tweens. Without this, a TweenLite.fromTo(obj, 1, {x:"+=100"}, {x:"-=100"}), for example, would actually jump to +=200 because the startAt would run twice, doubling the relative change.
                    this._startAt_.kill();
                }
                startVars = {};
                for (let p in v.startAt) { //copy the properties/values into a new object to avoid collisions, like var to = {x:0}, from = {x:500}; timeline.fromTo(e, 1, from, to).fromTo(e, 1, to, from);
                    startVars[p] = v.startAt[p];
                }
                startVars.data = "isStart";
                startVars.overwrite = 'false';
                startVars.immediateRender = true;
                startVars.lazy = (immediate && v.lazy !== false);
                startVars.startAt = startVars.delay = null; //no nesting of startAt objects allowed (otherwise it could cause an infinite loop).
                startVars.onUpdate = v.onUpdate;
                startVars.onUpdateParams = v.onUpdateParams;
                startVars.onUpdateScope = v.onUpdateScope || v.callbackScope || this;
                this._startAt_ = TweenLite.to(this.target || {}, 0, startVars);
                if (immediate) {
                    if (this._time_ > 0) {
                        this._startAt_ = null; //tweens that render immediately (like most from() and fromTo() tweens) shouldn't revert when their parent timeline's playhead goes backward past the startTime because the initial render could have happened anytime and it shouldn't be directly correlated to this tween's startTime. Imagine setting up a complex animation where the beginning states of various objects are rendered immediately but the tween doesn't happen for quite some time - if we revert to the starting values as soon as the playhead goes backward past the tween's startTime, it will throw things off visually. Reversion should only happen in TimelineLite/Max instances where immediateRender was false (which is the default in the convenience methods like from()).
                    } else if (dur !== 0) {
                        return; //we skip initialization here so that overwriting doesn't occur until the tween actually begins. Otherwise, if you create several immediateRender:true tweens of the same target/properties to drop into a TimelineLite or TimelineMax, the last one created would overwrite the first ones because they didn't get placed into the timeline yet before the first render occurs and kicks in overwriting.
                    }
                }
            } else if (v.runBackwards && dur !== 0) {
                //from() tweens must be handled uniquely: their beginning values must be rendered but we don't want overwriting to occur yet (when time is still 0). Wait until the tween actually begins before doing all the routines like overwriting. At that time, we should render at the END of the tween to ensure that things initialize correctly (remember, from() tweens go backwards)
                if (this._startAt_) {
                    this._startAt_.render(-1, true);
                    this._startAt_.kill();
                    this._startAt_ = null;
                } else {
                    if (this._time_ !== 0) { //in rare cases (like if a from() tween runs and then is invalidate()-ed), immediateRender could be true but the initial forced-render gets skipped, so there's no need to force the render in this context when the _time is greater than 0
                        immediate = false;
                    }
                    let pt: TweenVars = {};
                    for (let p in v) { //copy props into a new object and skip any reserved props, otherwise onComplete or onUpdate or onStart could fire. We should, however, permit autoCSS to go through.
                        if (!reservedPropsMap[p]) {
                            pt[p] = v[p];
                        }
                    }
                    pt.overwrite = 0;
                    pt.data = "isFromStart"; //we tag the tween with as "isFromStart" so that if [inside a plugin] we need to only do something at the very END of a tween, we have a way of identifying this tween as merely the one that's setting the beginning values for a "from()" tween. For example, clearProps in CSSPlugin should only get applied at the very END of a tween and without this tag, from(...{height:100, clearProps:"height", delay:1}) would wipe the height at the beginning of the tween and after 1 second, it'd kick back in.
                    pt.lazy = (immediate && v.lazy !== false);
                    pt.immediateRender = immediate; //zero-duration tweens render immediately by default, but if we're not specifically instructed to render this tween immediately, we should skip this and merely _init() to record the starting values (rendering them immediately would push them to completion which is wasteful in that case - we'd have to render(-1) immediately after)
                    this._startAt_ = TweenLite.to(this.target, 0, pt);
                    if (!immediate) {
                        this._startAt_._init_(); //ensures that the initial values are recorded
                        this._startAt_._enabled_(false); //no need to have the tween render on the next cycle. Disable it because we'll always manually control the renders of the _startAt tween.
                        if (this.vars.immediateRender) {
                            this._startAt_ = null;
                        }
                    } else if (this._time_ === 0) {
                        return;
                    }
                }
            }

            this._firstPT = null;

            if (this._targets_) {
                let l = this._targets_.length;
                for (let i = 0; i < l; i++) {
                    this._initProps(this._targets_[i], (this._propLookup_[i] = {}), this._siblings_[i], (op ? op[i] : null), i)
                }
            } else {
                this._initProps(this.target, this._propLookup_, this._siblings_, op, 0);
            }

            if (op) if (!this._firstPT) if (typeof (this.target) !== "function") { //if all tweening properties have been overwritten, kill the tween. If the target is a function, it's probably a delayedCall so let it live.
                this._enabled_(false, false);
            }
            if (v.runBackwards) {
                let pt = this._firstPT;
                while (pt) {
                    pt.s += pt.c;
                    pt.c = -pt.c;
                    pt = pt._next_;
                }
            }
            this._existOnUpdate_ = !!v.onUpdate;
            this._initted_ = true;
        };

        _initProps(target, propLookup, siblings, overwrittenProps, index) {
            var i, initPlugins, plugin, pt, v;
            if (target == null) {
                return false;
            }

            if (lazyLookupMap[target._gsTweenID_]) {
                lazyRenderTweens(); //if other tweens of the same target have recently initted but haven't rendered yet, we've got to force the render so that the starting values are correct (imagine populating a timeline with a bunch of sequential tweens and then jumping to the end)
            }

            for (let p in this.vars) {
                let v = this.vars[p];
                if (reservedPropsMap[p]) {
                    if (isArray(v) && v.join("").indexOf("{self}") !== -1) {
                        this.vars[p] = v = this._swapSelfInParams_(v);
                    }
                } else if (_plugins_[p] && (plugin = new _plugins_[p]())._onInitTween(target, this.vars[p], this, index)) {

                    let pt: TweenPropType = this._firstPT = { _next_: this._firstPT, t: plugin, p: "setRatio", s: 0, c: 1, f: true, n: p, pg: true, pr: plugin._priority, m: 0 };
                    i = plugin._overwriteProps.length;
                    while (--i > -1) {
                        propLookup[plugin._overwriteProps[i]] = this._firstPT;
                    }
                    if (plugin._priority || plugin._onInitAllProps) {
                        initPlugins = true;
                    }
                    if (plugin._onDisable || plugin._onEnable) {
                        this._notifyPluginsOfEnabled = true;
                    }
                    if (pt._next_) {
                        pt._next_._prev_ = pt;
                    }

                } else {
                    propLookup[p] = addPropTween.call(this, target, p, "get", v, p, 0, null, this.vars.stringFilter, index);
                }
            }

            if (overwrittenProps) if (this._kill_(overwrittenProps, target)) { //another tween may have tried to overwrite properties of this tween before init() was called (like if two tweens start at the same time, the one created second will run first)
                return this._initProps(target, propLookup, siblings, overwrittenProps, index);
            }
            if (this._overwrite_ > 1) if (this._firstPT) if (siblings.length > 1) if (applyOverwriteHook(target, this, propLookup, this._overwrite_, siblings)) {
                this._kill_(propLookup, target);
                return this._initProps(target, propLookup, siblings, overwrittenProps, index);
            }
            if (this._firstPT) if ((this.vars.lazy !== false && this._duration_) || (this.vars.lazy && !this._duration_)) { //zero duration tweens don't lazy render by default; everything else does.
                lazyLookupMap[target._gsTweenID_] = true;
            }
            return initPlugins;
        };

        render(time: number, suppressEvents?: boolean, force?: boolean) {
            let prevTime = this._time_;
            let duration = this._duration_;
            let prevRawPrevTime = this._rawPrevTime_;
            let isComplete: boolean;
            let callback: string;
            let rawPrevTime: number;
            let pt;

            if (time >= duration - 0.0000001 && time >= 0) { //to work around occasional floating point math artifacts.
                this._totalTime_ = this._time_ = duration;
                this._ratio_ = 1;
                if (!this._reversed_) {
                    isComplete = true;
                    callback = "onComplete";
                    force = (force || this._timeline_.autoRemoveChildren); //otherwise, if the animation is unpaused/activated after it's already finished, it doesn't get removed from the parent timeline.
                }
                if (duration === 0) if (this._initted_ || !this.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
                    if (this._startTime_ === this._timeline_._duration_) { //if a zero-duration tween is at the VERY end of a timeline and that timeline renders at its end, it will typically add a tiny bit of cushion to the render time to prevent rounding errors from getting in the way of tweens rendering their VERY end. If we then reverse() that timeline, the zero-duration tween will trigger its onReverseComplete even though technically the playhead didn't pass over it again. It's a very specific edge case we must accommodate.
                        time = 0;
                    }

                    //note: when this.data is "isPause", it's a callback added by addPause() on a timeline that we should not be triggered when LEAVING its exact start time. In other words, tl.addPause(1).play(1) shouldn't pause.
                    if (prevRawPrevTime < 0 || (time <= 0 && time >= -0.0000001) || (prevRawPrevTime === tinyNum && this.data !== "isPause")) if (prevRawPrevTime !== time) {
                        force = true;
                        if (prevRawPrevTime > tinyNum) {
                            callback = "onReverseComplete";
                        }
                    }
                    this._rawPrevTime_ = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
                }

            } else if (time < 0.0000001) { //to work around occasional floating point math artifacts, round super small values to 0.
                this._totalTime_ = this._time_ = 0;
                this._ratio_ = 0;
                if (prevTime !== 0 || (duration === 0 && prevRawPrevTime > 0)) {
                    callback = "onReverseComplete";
                    isComplete = this._reversed_;
                }
                if (time < 0) {
                    this._active_ = false;
                    if (duration === 0) if (this._initted_ || !this.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
                        if (prevRawPrevTime >= 0 && !(prevRawPrevTime === tinyNum && this.data === "isPause")) {
                            force = true;
                        }
                        this._rawPrevTime_ = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient.
                    }
                }
                if (!this._initted_ || (this._startAt_ && this._startAt_.progress())) { //if we render the very beginning (time == 0) of a fromTo(), we must force the render (normal tweens wouldn't need to render at a time of 0 when the prevTime was also 0). This is also mandatory to make sure overwriting kicks in immediately. Also, we check progress() because if startAt has already rendered at its end, we should force a render at its beginning. Otherwise, if you put the playhead directly on top of where a fromTo({immediateRender:false}) starts, and then move it backwards, the from() won't revert its values.
                    force = true;
                }
            } else {
                this._totalTime_ = this._time_ = time;
                this._ratio_ = time / duration;
            }

            if (this._time_ === prevTime && !force) {
                return;
            } else if (!this._initted_) {
                this._init_();
                if (!this._initted_ || this._gc_) { //immediateRender tweens typically won't initialize until the playhead advances (_time is greater than 0) in order to ensure that overwriting occurs properly. Also, if all of the tweening properties have been overwritten (which would cause _gc to be true, as set in _init()), we shouldn't continue otherwise an onStart callback could be called for example.
                    return;
                } else if (!force && this._firstPT && ((this.vars.lazy !== false && this._duration_) || (this.vars.lazy && !this._duration_))) {
                    this._time_ = this._totalTime_ = prevTime;
                    this._rawPrevTime_ = prevRawPrevTime;
                    lazyTweensArr.push(this);
                    this._lazy_ = [time, suppressEvents];
                    return;
                }
                //_ease is initially set to defaultEase, so now that init() has run, _ease is set properly and we need to recalculate the ratio. Overall this is faster than using conditional logic earlier in the method to avoid having to set ratio twice because we only init() once but renderTime() gets called VERY frequently.
                if (this._time_ && !isComplete) {
                    this._ratio_ = this._time_ / duration;
                } else if (isComplete) {
                    this._ratio_ = (this._time_ === 0) ? 0 : 1;
                }
            }
            if (this._lazy_ !== false) { //in case a lazy render is pending, we should flush it because the new render is occurring now (imagine a lazy tween instantiating and then immediately the user calls tween.seek(tween.duration()), skipping to the end - the end render would be forced, and then if we didn't flush the lazy render, it'd fire AFTER the seek(), rendering it at the wrong time.
                this._lazy_ = false;
            }
            if (!this._active_) if (!this._paused_ && this._time_ !== prevTime && time >= 0) {
                this._active_ = true;  //so that if the user renders a tween (as opposed to the timeline rendering it), the timeline is forced to re-render and align it with the proper time/frame on the next rendering cycle. Maybe the tween already finished but the user manually re-renders it as halfway done.
            }
            if (prevTime === 0) {
                if (this._startAt_) {
                    if (time >= 0) {
                        this._startAt_.render(time, true, force);
                    } else if (!callback) {
                        callback = "_dummyGS"; //if no callback is defined, use a dummy value just so that the condition at the end evaluates as true because _startAt should render AFTER the normal render loop when the time is negative. We could handle this in a more intuitive way, of course, but the render loop is the MOST important thing to optimize, so this technique allows us to avoid adding extra conditional logic in a high-frequency area.
                    }
                }
                if (this.vars.onStart) if (this._time_ !== 0 || duration === 0) if (!suppressEvents) {
                    this._callback_("onStart");
                }
            }
            pt = this._firstPT;
            while (pt) {
                if (pt.f) {
                    pt.t[pt.p](pt.c * this._ratio_ + pt.s);
                } else {
                    pt.t[pt.p] = pt.c * this._ratio_ + pt.s;
                }
                pt = pt._next_;
            }

            if (this._existOnUpdate_) {
                if (time < 0) if (this._startAt_ && time !== -0.0001) { //if the tween is positioned at the VERY beginning (_startTime_ 0) of its parent timeline, it's illegal for the playhead to go back further, so we should not render the recorded startAt values.
                    this._startAt_.render(time, true, force); //note: for performance reasons, we tuck this conditional logic inside less traveled areas (most tweens don't have an onUpdate). We'd just have it at the end before the onComplete, but the values should be updated before any onUpdate is called, so we ALSO put it here and then if it's not called, we do so later near the onComplete.
                }
                if (!suppressEvents) if (this._time_ !== prevTime || isComplete || force) {
                    this._callback_("onUpdate");
                }
            }
            if (callback) if (!this._gc_ || force) { //check _gc because there's a chance that kill() could be called in an onUpdate
                if (time < 0 && this._startAt_ && !this._existOnUpdate_ && time !== -0.0001) { //-0.0001 is a special value that we use when looping back to the beginning of a repeated TimelineMax, in which case we shouldn't render the _startAt values.
                    this._startAt_.render(time, true, force);
                }
                if (isComplete) {
                    if (this._timeline_.autoRemoveChildren) {
                        this._enabled_(false, false);
                    }
                    this._active_ = false;
                }
                if (!suppressEvents && this.vars[callback]) {
                    this._callback_(callback);
                }
                if (duration === 0 && this._rawPrevTime_ === tinyNum && rawPrevTime !== tinyNum) { //the onComplete or onReverseComplete could trigger movement of the playhead and for zero-duration tweens (which must discern direction) that land directly back on their start time, we don't want to fire again on the next render. Think of several addPause()'s in a timeline that forces the playhead to a certain spot, but what if it's already paused and another tween is tweening the "time" of the timeline? Each time it moves [forward] past that spot, it would move back, and since suppressEvents is true, it'd reset _rawPrevTime to _tinyNum so that when it begins again, the callback would fire (so ultimately it could bounce back and forth during that tween). Again, this is a very uncommon scenario, but possible nonetheless.
                    this._rawPrevTime_ = 0;
                }
            }
        };

        _kill_(vars, target, overwritingTween?) {
            if (vars === "all") {
                vars = null;
            }
            if (vars == null) if (target == null || target === this.target) {
                this._lazy_ = false;
                return this._enabled_(false, false);
            }
            target = (typeof (target) !== "string") ? (target || this._targets_ || this.target) : target;
            var simultaneousOverwrite = (overwritingTween && this._time_ && overwritingTween._startTime_ === this._startTime_ && this._timeline_ === overwritingTween._timeline_),
                i, overwrittenProps, p, pt, propLookup, changed, killProps, record, killed;
            if ((isArray(target))) {
                i = target.length;
                while (--i > -1) {
                    if (this._kill_(vars, target[i], overwritingTween)) {
                        changed = true;
                    }
                }
            } else {
                if (this._targets_) {
                    i = this._targets_.length;
                    while (--i > -1) {
                        if (target === this._targets_[i]) {
                            propLookup = this._propLookup_[i] || {};
                            this._overwrittenProps = this._overwrittenProps || [];
                            overwrittenProps = this._overwrittenProps[i] = vars ? this._overwrittenProps[i] || {} : "all";
                            break;
                        }
                    }
                } else if (target !== this.target) {
                    return false;
                } else {
                    propLookup = this._propLookup_;
                    overwrittenProps = this._overwrittenProps = vars ? this._overwrittenProps || {} : "all";
                }

                if (propLookup) {
                    killProps = vars || propLookup;
                    record = (vars !== overwrittenProps && overwrittenProps !== "all" && vars !== propLookup && (typeof (vars) !== "object" || !vars._tempKill)); //_tempKill is a super-secret way to delete a particular tweening property but NOT have it remembered as an official overwritten property (like in BezierPlugin)
                    if (overwritingTween && (TweenLite.onOverwrite || this.vars.onOverwrite)) {
                        for (p in killProps) {
                            if (propLookup[p]) {
                                if (!killed) {
                                    killed = [];
                                }
                                killed.push(p);
                            }
                        }
                        if ((killed || !vars) && !onOverwriteHook(this, overwritingTween, target, killed)) { //if the onOverwrite returned false, that means the user wants to override the overwriting (cancel it).
                            return false;
                        }
                    }

                    for (p in killProps) {
                        if ((pt = propLookup[p])) {
                            if (simultaneousOverwrite) { //if another tween overwrites this one and they both start at exactly the same time, yet this tween has already rendered once (for example, at 0.001) because it's first in the queue, we should revert the values to where they were at 0 so that the starting values aren't contaminated on the overwriting tween.
                                if (pt.f) {
                                    pt.t[pt.p](pt.s);
                                } else {
                                    pt.t[pt.p] = pt.s;
                                }
                                changed = true;
                            }
                            if (pt.pg && pt.t._kill(killProps)) {
                                changed = true; //some plugins need to be notified so they can perform cleanup tasks first
                            }
                            if (!pt.pg || pt.t._overwriteProps.length === 0) {
                                if (pt._prev_) {
                                    pt._prev_._next_ = pt._next_;
                                } else if (pt === this._firstPT) {
                                    this._firstPT = pt._next_;
                                }
                                if (pt._next_) {
                                    pt._next_._prev_ = pt._prev_;
                                }
                                pt._next_ = pt._prev_ = null;
                            }
                            delete propLookup[p];
                        }
                        if (record) {
                            overwrittenProps[p] = 1;
                        }
                    }
                    if (!this._firstPT && this._initted_) { //if all tweening properties are killed, kill the tween. Without this line, if there's a tween with multiple targets and then you killTweensOf() each target individually, the tween would technically still remain active and fire its onComplete even though there aren't any more properties tweening.
                        this._enabled_(false, false);
                    }
                }
            }
            return changed;
        };

        invalidate() {
            this._firstPT = this._overwrittenProps = this._startAt_ = this._existOnUpdate_ = null;
            this._notifyPluginsOfEnabled = this._active_ = this._lazy_ = false;
            this._propLookup_ = (this._targets_) ? {} : [];
            Animation.prototype.invalidate.call(this);
            if (this.vars.immediateRender) {
                this._time_ = -tinyNum; //forces a render without having to set the render() "force" parameter to true because we want to allow lazying by default (using the "force" parameter always forces an immediate full render)
                this.render(Math.min(0, -this._delay_)); //in case delay is negative.
            }
            return this;
        };

        _enabled_(enabled, ignoreTimeline?) {
            if (enabled && this._gc_) {
                var targets = this._targets_,
                    i;
                if (targets) {
                    i = targets.length;
                    while (--i > -1) {
                        this._siblings_[i] = targetRegister(targets[i], this, true);
                    }
                } else {
                    this._siblings_ = targetRegister(this.target, this, true);
                }
            }
            Animation.prototype._enabled_.call(this, enabled, ignoreTimeline);
            return false;
        };

    }
    var TweenLite_prototype = TweenLite.prototype;
    TweenLite_prototype.kill()._gc_ = false;

    //----TweenLite defaults, overwrite management, and root updates ----------------------------------------------------
    TweenLite_prototype._ratio_ = 0;
    TweenLite_prototype._firstPT = TweenLite_prototype._targets_ = TweenLite_prototype._overwrittenProps = TweenLite_prototype._startAt_ = null;
    TweenLite_prototype._notifyPluginsOfEnabled = TweenLite_prototype._lazy_ = false;

    TweenLite.version = "2.0.1";
    TweenLite.defaultOverwrite = "auto";
    TweenLite.ticker = gTicker;
    TweenLite.autoSleep = 120;
    TweenLite.lagSmoothing = function (threshold, adjustedLag) {
        gTicker.lagSmoothing(threshold, adjustedLag);
    };

    var lazyTweensArr: TweenLite[] = [],
        lazyLookupMap: { [key: string]: boolean } = {},
        _numbersExp = /(?:(-|-=|\+=)?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/ig,
        _relExp = /[\+-]=-?[\.\d]/,
        //_nonNumbersExp = /(?:([\-+](?!(\d|=)))|[^\d\-+=e]|(e(?![\-+][\d])))+/ig,
        setRatio = function (v) {
            var pt = this._firstPT,
                min = 0.000001,
                val;
            while (pt) {
                val = !pt.blob ? pt.c * v + pt.s : (v === 1 && this.end != null) ? this.end : v ? this.join("") : this.start;
                if (pt.m) {
                    val = pt.m.call(this._tween, val, this._target || pt.t, this._tween);
                } else if (val < min) if (val > -min && !pt.blob) { //prevents issues with converting very small numbers to strings in the browser
                    val = 0;
                }
                if (!pt.f) {
                    pt.t[pt.p] = val;
                } else if (pt.fp) {
                    pt.t[pt.p](pt.fp, val);
                } else {
                    pt.t[pt.p](val);
                }
                pt = pt._next_;
            }
        },
        //compares two strings (start/end), finds the numbers that are different and spits back an array representing the whole value but with the changing values isolated as elements. For example, "rgb(0,0,0)" and "rgb(100,50,0)" would become ["rgb(", 0, ",", 50, ",0)"]. Notice it merges the parts that are identical (performance optimization). The array also has a linked list of PropTweens attached starting with _firstPT that contain the tweening data (t, p, s, c, f, etc.). It also stores the starting value as a "start" property so that we can revert to it if/when necessary, like when a tween rewinds fully. If the quantity of numbers differs between the start and end, it will always prioritize the end value(s). The pt parameter is optional - it's for a PropTween that will be appended to the end of the linked list and is typically for actually setting the value after all of the elements have been updated (with array.join("")).
        blobDif = function (start, end, filter, pt) {
            var a = [],
                charIndex = 0,
                s = "",
                color = 0,
                startNums, endNums, num, i, l, nonNumbers, currentNum;
            (a as any).start = start;
            (a as any).end = end;
            start = a[0] = start + ""; //ensure values are strings
            end = a[1] = end + "";
            if (filter) {
                filter(a); //pass an array with the starting and ending values and let the filter do whatever it needs to the values.
                start = a[0];
                end = a[1];
            }
            a.length = 0;
            startNums = start.match(_numbersExp) || [];
            endNums = end.match(_numbersExp) || [];
            if (pt) {
                pt._next_ = null;
                pt.blob = 1;
                (a as any)._firstPT = (a as any)._applyPT = pt; //apply last in the linked list (which means inserting it first)
            }
            l = endNums.length;
            for (i = 0; i < l; i++) {
                currentNum = endNums[i];
                nonNumbers = end.substr(charIndex, end.indexOf(currentNum, charIndex) - charIndex);
                s += (nonNumbers || !i) ? nonNumbers : ","; //note: SVG spec allows omission of comma/space when a negative sign is wedged between two numbers, like 2.5-5.3 instead of 2.5,-5.3 but when tweening, the negative value may switch to positive, so we insert the comma just in case.
                charIndex += nonNumbers.length;
                if (color) { //sense rgba() values and round them.
                    color = (color + 1) % 5;
                } else if (nonNumbers.substr(-5) === "rgba(") {
                    color = 1;
                }
                if (currentNum === startNums[i] || startNums.length <= i) {
                    s += currentNum;
                } else {
                    if (s) {
                        a.push(s);
                        s = "";
                    }
                    num = parseFloat(startNums[i]);
                    a.push(num);
                    (a as any)._firstPT = { _next_: (a as any)._firstPT, t: a, p: a.length - 1, s: num, c: ((currentNum.charAt(1) === "=") ? parseInt(currentNum.charAt(0) + "1", 10) * parseFloat(currentNum.substr(2)) : (parseFloat(currentNum) - num)) || 0, f: 0, m: (color && color < 4) ? Math.round : 0 };
                    //note: we don't set _prev_ because we'll never need to remove individual PropTweens from this list.
                }
                charIndex += currentNum.length;
            }
            s += end.substr(charIndex);
            if (s) {
                a.push(s);
            }
            (a as any).setRatio = setRatio;
            if (_relExp.test(end)) { //if the end string contains relative values, delete it so that on the final render (in _setRatio()), we don't actually set it to the string with += or -= characters (forces it to use the calculated value).
                (a as any).end = null;
            }
            return a;
        },
        //note: "funcParam" is only necessary for function-based getters/setters that require an extra parameter like getAttribute("width") and setAttribute("width", value). In this example, funcParam would be "width". Used by AttrPlugin for example.
        addPropTween = function (this: TweenLite, target, prop, start, end, overwriteProp, mod, funcParam, stringFilter, index) {
            if (typeof (end) === "function") {
                end = end(index || 0, target);
            }
            var type = typeof (target[prop]),
                getterName = (type !== "function") ? "" : ((prop.indexOf("set") || typeof (target["get" + prop.substr(3)]) !== "function") ? prop : "get" + prop.substr(3)),
                s = (start !== "get") ? start : !getterName ? target[prop] : funcParam ? target[getterName](funcParam) : target[getterName](),
                isRelative = (typeof (end) === "string" && end.charAt(1) === "="),
                pt: any = { t: target, p: prop, s: s, f: (type === "function"), pg: 0, n: overwriteProp || prop, m: (!mod ? 0 : (typeof (mod) === "function") ? mod : Math.round), pr: 0, c: isRelative ? parseInt(end.charAt(0) + "1", 10) * parseFloat(end.substr(2)) : (parseFloat(end) - s) || 0 },
                blob;

            if (typeof (s) !== "number" || (typeof (end) !== "number" && !isRelative)) {
                if (funcParam || isNaN(s) || (!isRelative && isNaN(end)) || typeof (s) === "boolean" || typeof (end) === "boolean") {
                    //a blob (string that has multiple numbers in it)
                    pt.fp = funcParam;
                    blob = blobDif(s, (isRelative ? (parseFloat(pt.s) + pt.c) + (pt.s + "").replace(/[0-9\-\.]/g, "") : end), stringFilter, pt);
                    pt = { t: blob, p: "setRatio", s: 0, c: 1, f: 2, pg: 0, n: overwriteProp || prop, pr: 0, m: 0 }; //"2" indicates it's a Blob property tween. Needed for RoundPropsPlugin for example.
                } else {
                    pt.s = parseFloat(s);
                    if (!isRelative) {
                        pt.c = (parseFloat(end) - pt.s) || 0;
                    }
                }
            }
            if (pt.c) { //only add it to the linked list if there's a change.
                if ((pt._next_ = this._firstPT)) {
                    pt._next_._prev_ = pt;
                }
                this._firstPT = pt;
                return pt;
            }
        },
        _internals_: any = TweenLite._internals_ = { isArray: isArray, lazyTweens: lazyTweensArr, blobDif: blobDif }, //gives us a way to expose certain private values to other GreenSock classes without contaminating tha main TweenLite object.
        _plugins_ = TweenLite._plugins_ = {},
        tweenLookupMap: { [key: string]: { target: any, tweens: TweenLite[] } } = _internals_.tweenLookup = {},
        tweenLookupIndex = 0,
        reservedPropsMap = _internals_.reservedProps = { ease: 1, delay: 1, overwrite: 1, onComplete: 1, onCompleteParams: 1, onCompleteScope: 1, useFrames: 1, runBackwards: 1, startAt: 1, onUpdate: 1, onUpdateParams: 1, onUpdateScope: 1, onStart: 1, onStartParams: 1, onStartScope: 1, onReverseComplete: 1, onReverseCompleteParams: 1, onReverseCompleteScope: 1, onRepeat: 1, onRepeatParams: 1, onRepeatScope: 1, easeParams: 1, yoyo: 1, immediateRender: 1, repeat: 1, repeatDelay: 1, data: 1, paused: 1, reversed: 1, autoCSS: 1, lazy: 1, onOverwrite: 1, callbackScope: 1, stringFilter: 1, id: 1, yoyoEase: 1 },
        overwriteLookupMap = { none: 0, all: 1, auto: 2, concurrent: 3, allOnStart: 4, preexisting: 5, "true": 1, "false": 0 },
        gRootFramesTimeline = Animation.rootFramesTimeline = new SimpleTimeline(),
        gRootTimeline = Animation.rootTimeline = new SimpleTimeline(),
        nextGCFrame = 30,
        lazyRenderTweens = _internals_.lazyRender = function () {
            let i = lazyTweensArr.length;
            lazyLookupMap = {};
            while (--i > -1) {
                let tween = lazyTweensArr[i];
                if (tween && tween._lazy_ !== false) {
                    tween.render(tween._lazy_[0], tween._lazy_[1], true);
                    tween._lazy_ = false;
                }
            }
            lazyTweensArr.length = 0;
        };

    gRootTimeline._startTime_ = gTicker.time;
    gRootFramesTimeline._startTime_ = gTicker.frame;
    gRootTimeline._active_ = gRootFramesTimeline._active_ = true;

    TweenLite.render = function () {
        if (lazyTweensArr.length) { //if code is run outside of the requestAnimationFrame loop, there may be tweens queued AFTER the engine refreshed, so we need to ensure any pending renders occur before we refresh again.
            lazyRenderTweens();
        }
        gRootTimeline.render((gTicker.time - gRootTimeline._startTime_) * gRootTimeline._timeScale_, false, false);
        gRootFramesTimeline.render((gTicker.frame - gRootFramesTimeline._startTime_) * gRootFramesTimeline._timeScale_, false, false);
        if (lazyTweensArr.length) {
            lazyRenderTweens();
        }
        if (gTicker.frame >= nextGCFrame) { //dump garbage every 120 frames or whatever the user sets TweenLite.autoSleep to
            nextGCFrame = gTicker.frame + (parseInt(TweenLite.autoSleep + '', 10) || 120);
            for (let p in tweenLookupMap) {
                let tweens = tweenLookupMap[p].tweens;
                let i = tweens.length;
                while (--i > -1) {
                    if (tweens[i]._gc_) {
                        tweens.splice(i, 1);
                    }
                }
                if (tweens.length === 0) {
                    delete tweenLookupMap[p];
                }
            }
            //if there are no more tweens in the root timelines, or if they're all paused, make the _timer sleep to reduce load on the CPU slightly
            let tween = gRootTimeline._first_;
            if (!tween || tween._paused_) if (TweenLite.autoSleep && !gRootFramesTimeline._first_ && gTicker.listeners[Ticker.TickWord].length === 1) {
                while (tween && tween._paused_) {
                    tween = tween._next_;
                }
                if (!tween) {
                    gTicker.sleep();
                }
            }
        }
    };

    gTicker.addEventListener(Ticker.TickWord, TweenLite.render);

    function targetRegister(target: any, tween?: TweenLite, scrub?: boolean) {
        let id: string = target._gsTweenID_;

        if (!tweenLookupMap[id || (target._gsTweenID_ = id = "t" + (tweenLookupIndex++))]) {
            tweenLookupMap[id] = { target: target, tweens: [] };
        }
        if (tween) {
            let i: number;
            let a = tweenLookupMap[id].tweens;
            a[(i = a.length)] = tween;
            if (scrub) {
                while (--i > -1) {
                    if (a[i] === tween) {
                        a.splice(i, 1);
                    }
                }
            }
        }
        return tweenLookupMap[id].tweens;
    }

    function onOverwriteHook(overwrittenTween, overwritingTween, target?, killedProps?) {
        var func = overwrittenTween.vars.onOverwrite, r1, r2;
        if (func) {
            r1 = func(overwrittenTween, overwritingTween, target, killedProps);
        }
        func = TweenLite.onOverwrite;
        if (func) {
            r2 = func(overwrittenTween, overwritingTween, target, killedProps);
        }
        return (r1 !== false && r2 !== false);
    }
    function applyOverwriteHook(target: any, tween: TweenLite, props, overwriteMode: number, siblings: TweenLite[]) {
        var changed: boolean, curTween: TweenLite, l;
        if (overwriteMode === 1 || overwriteMode >= 4) {
            l = siblings.length;
            for (let i = 0; i < l; i++) {
                if ((curTween = siblings[i]) !== tween) {
                    if (!curTween._gc_) {
                        if (curTween._kill_(null, target)) {
                            changed = true;
                        }
                    }
                } else if (overwriteMode === 5) {
                    break;
                }
            }
            return changed;
        }
        //NOTE: Add 0.0000000001 to overcome floating point errors that can cause the startTime to be VERY slightly off (when a tween's time() is set for example)
        var startTime = tween._startTime_ + tinyNum,
            overlaps = [],
            oCount = 0,
            zeroDur = (tween._duration_ === 0),
            globalStart;
        let i = siblings.length;
        while (--i > -1) {
            if ((curTween = siblings[i]) === tween || curTween._gc_ || curTween._paused_) {
                //ignore
            } else if (curTween._timeline_ !== tween._timeline_) {
                globalStart = globalStart || checkOverlapHook(tween, 0, zeroDur);
                if (checkOverlapHook(curTween, globalStart, zeroDur) === 0) {
                    overlaps[oCount++] = curTween;
                }
            } else if (curTween._startTime_ <= startTime) if (curTween._startTime_ + curTween.totalDuration() / curTween._timeScale_ > startTime) if (!((zeroDur || !curTween._initted_) && startTime - curTween._startTime_ <= 0.0000000002)) {
                overlaps[oCount++] = curTween;
            }
        }

        i = oCount;
        while (--i > -1) {
            curTween = overlaps[i];
            if (overwriteMode === 2) if (curTween._kill_(props, target, tween)) {
                changed = true;
            }
            if (overwriteMode !== 2 || (!curTween._firstPT && curTween._initted_)) {
                if (overwriteMode !== 2 && !onOverwriteHook(curTween, tween)) {
                    continue;
                }
                if (curTween._enabled_(false, false)) { //if all property tweens have been overwritten, kill the tween.
                    changed = true;
                }
            }
        }
        return changed;
    }
    function checkOverlapHook(tween, reference, zeroDur) {
        var tl = tween._timeline_,
            ts = tl._timeScale_,
            t = tween._startTime_;
        while (tl._timeline_) {
            t += tl._startTime_;
            ts *= tl._timeScale_;
            if (tl._paused_) {
                return -100;
            }
            tl = tl._timeline_;
        }
        t /= ts;
        return (t > reference) ? t - reference : ((zeroDur && t === reference) || (!tween._initted_ && t - reference < 2 * tinyNum)) ? tinyNum : ((t += tween.totalDuration() / tween._timeScale_ / ts) > reference + tinyNum) ? 0 : t - reference - tinyNum;
    };


    //----TweenLite static methods -----------------------------------------------------
    TweenLite.to = function (target, duration, vars) {
        return new TweenLite(target, duration, vars);
    };

    TweenLite.from = function (target, duration, vars) {
        vars.runBackwards = true;
        vars.immediateRender = (vars.immediateRender != false);
        return new TweenLite(target, duration, vars);
    };

    TweenLite.fromTo = function (target, duration, fromVars, toVars) {
        toVars.startAt = fromVars;
        toVars.immediateRender = (toVars.immediateRender != false && fromVars.immediateRender != false);
        return new TweenLite(target, duration, toVars);
    };

    TweenLite.delayedCall = function (delay, callback, params?, scope?, useFrames?) {
        return new TweenLite(callback, 0, { delay: delay, onComplete: callback, onCompleteParams: params, callbackScope: scope, onReverseComplete: callback, onReverseCompleteParams: params, immediateRender: false, lazy: false, useFrames: useFrames, overwrite: 0 });
    };

    TweenLite.set = function (target, vars) {
        return new TweenLite(target, 0, vars);
    };

    TweenLite.getTweensOf = function (target, onlyActive?) {
        if (target == null) { return []; }
        target = (typeof (target) !== "string") ? target : target;
        var i, a, j, t;
        if ((isArray(target))) {
            i = target.length;
            a = [];
            while (--i > -1) {
                a = a.concat(TweenLite.getTweensOf(target[i], onlyActive));
            }
            i = a.length;
            //now get rid of any duplicates (tweens of arrays of objects could cause duplicates)
            while (--i > -1) {
                t = a[i];
                j = i;
                while (--j > -1) {
                    if (t === a[j]) {
                        a.splice(i, 1);
                    }
                }
            }
        } else if (target._gsTweenID_) {
            a = targetRegister(target).concat();
            i = a.length;
            while (--i > -1) {
                if (a[i]._gc || (onlyActive && !a[i].isActive())) {
                    a.splice(i, 1);
                }
            }
        }
        return a || [];
    };

    TweenLite.killTweensOf = TweenLite.killDelayedCallsTo = function (target, onlyActive, vars) {
        if (typeof (onlyActive) === "object") {
            vars = onlyActive; //for backwards compatibility (before "onlyActive" parameter was inserted)
            onlyActive = false;
        }
        var a = TweenLite.getTweensOf(target, onlyActive),
            i = a.length;
        while (--i > -1) {
            a[i]._kill(vars, target);
        }
    };
}
